package github.kawaiior.yuanchuxiuzhen.common.entity.addon.model;

import com.mojang.blaze3d.matrix.MatrixStack;
import com.mojang.blaze3d.vertex.IVertexBuilder;
import github.kawaiior.yuanchuxiuzhen.common.entity.addon.PuBirdEntity;
import net.minecraft.client.renderer.entity.model.EntityModel;
import net.minecraft.client.renderer.model.ModelRenderer;
import net.minecraft.util.math.MathHelper;

public class PuBirdEntityModel extends EntityModel<PuBirdEntity> {

    private final ModelRenderer leftarm;
    private final ModelRenderer rightarm;
    private final ModelRenderer body;
    private final ModelRenderer head;

    public PuBirdEntityModel(){
        this.textureWidth = 36;
        this.textureHeight = 52;

        this.leftarm = new ModelRenderer(this);
        this.leftarm.setRotationPoint(4.0F, 14.0F, 0.0F);
        addBox(this.leftarm, 0, 47, -1.0F, 0.0F, -2.0F, 8, 1, 4, 0.0F, false);
        this.rightarm = new ModelRenderer(this);
        this.rightarm.setRotationPoint(-4.0F, 14.0F, 0.0F);
        addBox(this.rightarm, 0, 47, -7.0F, 0.0F, -2.0F, 8, 1, 4, 0.0F, false);
        this.body = new ModelRenderer(this);
        this.body.setRotationPoint(0.0F, 24.0F, 0.0F);
        addBox(this.body, 0, 0, -4.0F, -12.0F, -4.0F, 8, 8, 8, 0.0F, false);
        addBox(this.body, 0, 28, -1.5F, -5.0F, -2.0F, 3, 3, 4, 0.0F, false);
        addBox(this.body, 24, 16, -0.1F, -9.0F, 3.0F, 0, 4, 6, 0.0F, false);
        addBox(this.body, 0, 16, -3.0F, -11.0F, -3.0F, 6, 6, 6, 0.0F, false);
        this.head = new ModelRenderer(this);
        this.head.setRotationPoint(0.0F, 24.0F, 0.0F);
        addBox(this.head, 0, 35, -3.0F, -17.0F, -8.0F, 6, 6, 6, 0.0F, false);
    }

    private void addBox(ModelRenderer mb, int tx, int ty, float x, float y, float z, float width, float height, float depth, float delta, boolean mirrorIn){
        ModelRenderer mr = new ModelRenderer(this);
        mb.addChild(mr);
        mr.setTextureOffset(tx, ty).addBox(x,y,z,width,height,depth,delta,mirrorIn);
    }

    @Override
    public void setRotationAngles(PuBirdEntity entityIn, float limbSwing, float limbSwingAmount, float ageInTicks, float netHeadYaw, float headPitch) {
        this.head.rotateAngleY = netHeadYaw / 57.295776F;
        this.head.rotateAngleX = headPitch / 57.295776F;
        this.rightarm.rotateAngleX = MathHelper.cos(limbSwing * 0.6662F + 3.1415927F) * limbSwingAmount;
        this.leftarm.rotateAngleY = MathHelper.cos(limbSwing * 0.6662F) * limbSwingAmount;
    }

    @Override
    public void render(MatrixStack matrixStackIn, IVertexBuilder bufferIn, int packedLightIn, int packedOverlayIn, float red, float green, float blue, float alpha) {
        this.leftarm.render(matrixStackIn, bufferIn, packedLightIn, packedOverlayIn);
        this.rightarm.render(matrixStackIn, bufferIn, packedLightIn, packedOverlayIn);
        this.body.render(matrixStackIn, bufferIn, packedLightIn, packedOverlayIn);
        this.head.render(matrixStackIn, bufferIn, packedLightIn, packedOverlayIn);
    }
}
